﻿using CI.Interfaces;
using CI.Organism;

namespace CI.Mesopotamia
{
    /// <summary>Pair of organisms used in collision detection</summary>
    public class CollisionPair
    {
        /// <summary>
        /// Organism 1
        /// </summary>
        public IOrganism Organism1
        {
            get { return _organism1; }
            set { _organism1 = value; }
        }
        private IOrganism _organism2;


        /// <summary>
        /// Organism 2
        /// </summary>
        public IOrganism Organism2
        {
            get { return _organism2; }
            set { _organism2 = value; }
        }
        private IOrganism _organism1;

        /// <summary>
        /// Create with passed organisms
        /// </summary>
        /// <param name="organism1">first childOrganism</param>
        /// <param name="organism2">second childOrganism</param>
        public CollisionPair(IOrganism organism1, IOrganism organism2)
        {
            this._organism1 = organism1;
            this._organism2 = organism2;
        }

        /// <summary>
        /// Compare to see if two objects are equal
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool Equals(object value)
        {
            // check the pairs organisms
            if ((this._organism1 == ((CollisionPair)value)._organism1) && (this._organism2 == ((CollisionPair)value)._organism2))
                return true;

            // check the pairs in case they are swapped
            if ((this._organism1 == ((CollisionPair)value)._organism2) && (this._organism2 == ((CollisionPair)value)._organism1))
                return true;

            // else all not found
            return false;
        }

        /// <summary>
        /// Get the hash code
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}